import 'package:flutter/material.dart';
import 'package:mall/constant/app_colors.dart';
import 'package:mall/constant/app_dimens.dart';
import 'package:mall/constant/app_strings.dart';
import 'package:mall/constant/text_style.dart';
import 'package:mall/modules/model/home_entity.dart';
import 'package:mall/ui/widgets/cached_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class TabHomeGroupByWidget extends StatelessWidget {
  final List<HomeModelGrouponlist> homeModelGroupLists;

  TabHomeGroupByWidget(this.homeModelGroupLists);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          margin: EdgeInsets.only(left: 15, top: 15, bottom: 15),
          alignment: Alignment.centerLeft,
          child: Text(AppStrings.GROUP_BUG, style: FMTextStyle.color_333333_size_13_bold),
        ),
        ListView.builder(
            padding: EdgeInsets.all(0),
            physics: NeverScrollableScrollPhysics(),
            shrinkWrap: true,
            itemCount: homeModelGroupLists.length,
            itemBuilder: (BuildContext context, int index) {
              return _getGroupBuyItem(homeModelGroupLists[index]);
            })
      ],
    );
  }

  Widget _getGroupBuyItem(HomeModelGrouponlist groupBuyEntity) {
    return Container(
        margin: EdgeInsets.only(left: 15, right: 15),
        child: Card(
            child: Container(
          padding: EdgeInsets.only(top: 10, bottom: 10),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              CachedImageView(65, 65, groupBuyEntity.picUrl),
              Container(
                padding: EdgeInsets.only(
                  left: 10,
                ),
                width: ScreenUtil().setWidth(AppDimens.DIMENS_500),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text(groupBuyEntity.name ?? "", style: FMTextStyle.color_222222_size_13),
                    Padding(
                      padding: EdgeInsets.only(top: 15),
                    ),
                    Text(
                      groupBuyEntity.brief ?? "",
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: FMTextStyle.color_999999_size_13,
                    ),
                    Padding(
                      padding: EdgeInsets.only(top: 15),
                    ),
                    Row(
                      children: <Widget>[
                        Text(
                          "${AppStrings.ORIGINAL_PRICE}${groupBuyEntity.retailPrice}",
                          style: TextStyle(
                              fontSize: 13,
                              color: AppColors.C_999999,
                              decoration: TextDecoration.lineThrough,
                              decorationStyle: TextDecorationStyle.dashed),
                        ),
                        Padding(
                          padding: EdgeInsets.only(left: 15),
                        ),
                        Text("${AppStrings.CURRENT_PRICE}${groupBuyEntity.retailPrice}",
                            style: FMTextStyle.color_ff5722_size_13),
                      ],
                    ),
                  ],
                ),
              ),
              Expanded(
                  child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.end,
                children: <Widget>[
                  Container(
                    height: ScreenUtil().setHeight(AppDimens.DIMENS_50),
                    padding: EdgeInsets.only(
                        left: ScreenUtil().setWidth(AppDimens.DIMENS_10),
                        right: ScreenUtil().setWidth(AppDimens.DIMENS_10)),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        border: new Border.all(color: AppColors.C_FF5722, width: 1),
                        // 边色与边宽度
                        borderRadius: BorderRadius.circular(AppDimens.DIMENS_10),
                        color: Colors.white),
                    child: Text(
                      "${groupBuyEntity.grouponMember}${AppStrings.GROUP_FORMATION}",
                      style: FMTextStyle.color_ff5722_size_12,
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(left: ScreenUtil().setWidth(AppDimens.DIMENS_10), right: 10),
                    height: ScreenUtil().setHeight(AppDimens.DIMENS_50),
                    padding: EdgeInsets.only(
                        left: ScreenUtil().setWidth(AppDimens.DIMENS_10),
                        right: ScreenUtil().setWidth(AppDimens.DIMENS_10)),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        border: new Border.all(color: AppColors.C_FF5722, width: 1),
                        // 边色与边宽度
                        borderRadius: BorderRadius.circular(AppDimens.DIMENS_10),
                        color: Colors.white),
                    child: Text(
                      "${AppStrings.REDUCTION}${groupBuyEntity.grouponMember}",
                      style: FMTextStyle.color_ff5722_size_12,
                    ),
                  ),
                ],
              )),
            ],
          ),
        )));
  }
}
